﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reviewer.Entities;
using Reviewer.Data.Bases;
using MySql.Data.MySqlClient;
using Reviewer.Utilities.Data;

namespace Reviewer.Data
{
    /// <summary>
    /// SystemText repository
    /// </summary>
    [CLSCompliant(false)]
    public class SystemTextRepository : RepositoryCrudBase<SystemText, Int32>
    {
        #region fields (private)
        private const string TABLE_NAME = "glo_texts";
        private static readonly CrudColumnInfo columnId = new CrudColumnInfo(0, "ID", MySqlDbType.Int32, true, false, false, true);
        private static readonly CrudColumnInfo columnText = new CrudColumnInfo(1, "Tekst", MySqlDbType.Text, false, false, false);
        #endregion

        internal override CrudColumnInfo[] Columns
        {
            get
            {
                return new CrudColumnInfo[]{
                    SystemTextRepository.columnId
                    , SystemTextRepository.columnText
                };
            }
        }

        protected override string TableName
        {
            get { return SystemTextRepository.TABLE_NAME; }
        }

        internal override object ColumnToValue(CrudColumnInfo info, SystemText item)
        {
            if (info.Equals(SystemTextRepository.columnId)) return item.Id;
            else if (info.Equals(SystemTextRepository.columnText)) return item.Text;
            return null;
        }

        protected override SystemText BuildItemFromReader(System.Data.IDataReader reader)
        {
            SystemText item = new SystemText();
            if (reader != null)
            {
                item.Id = DataReaderUtility.GetValue(reader, reader.GetOrdinal(SystemTextRepository.columnId.Name), 0);
                item.Text = DataReaderUtility.GetValue(reader, reader.GetOrdinal(SystemTextRepository.columnText.Name), String.Empty);
            }
            return item;
        }
    }
}
